<template>
  <div class="navs">
      <ul>
          <swiper :options="swiperOption">
            <!-- slides -->
            <swiper-slide v-for="(page, index) of pages" :key="index">
                <li class="nav-item" v-for="item of page" :key="item.id">
                    <img class="item-img" :src="item.imgUrl" alt="">
                    <p class="item-txt">{{ item.desc }}</p>
                </li>
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination"  slot="pagination"></div>
          </swiper>
      </ul>
  </div>
</template>

<script>
export default {
  name: 'HomeNavs',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      let pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/mixins.styl';
    .navs >>> .swiper-container
        overflow visible
    .navs >>> .swiper-pagination-bullets
        bottom -.4rem
    .navs
        height 4.5rem
        padding .1rem 0
        .nav-item
            width 25%
            float left
            padding .1rem 0
            text-align center
            .item-img
                width 64%
            .item-txt
                color #424242
                padding-top: .2rem;
                ellipsis()
</style>
